<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('虚拟用况组模式选择')" />
    <th:block th:include="include :: select2-css" />
    <style type="text/css">

    </style>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-interface-add">
            <input type="hidden" id="id" name="id" th:value="${virtualUsageGroup.id}">

            <div class="form-group">
                <label class="col-sm-5 control-label">约定模式：</label>
                <div class="col-sm-6">
                    <select name="model" id="model" class="form-control m-b" th:with="type=${@dict.getType('virtualUsageModel')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="${virtualUsageGroup.model}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-5 control-label">约定模式备注：</label>
                <div class="col-sm-6">
                    <p class="form-control-static" id="remark"></p>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-5 control-label">自定义模式：</label>
                <div class="col-sm-6">
                    <textarea name="selfModel" class="form-control">[[${virtualUsageGroup.selfModel}]]</textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "virtualUsageGroup/virtualUsageGroup";
        $("#form-interface-add").validate({
            focusCleanup: true
        });
        var virtualUsageModel = [[${@dict.getType('virtualUsageModel')}]];

        $(function () {
            $('#model').on('select2:select', function (e) {
                var value = $('#model').select2('val');
                for (var i=0; i<virtualUsageModel.length; i++) {
                    if (virtualUsageModel[i].dictValue == value) {
                        $("#remark").text(virtualUsageModel[i].remark);
                        break;
                    }
                }
            });
            var model = $('#model').select2('val');
            if (model) {
                for (var i=0; i<virtualUsageModel.length; i++) {
                    if (virtualUsageModel[i].dictValue == model) {
                        $("#remark").text(virtualUsageModel[i].remark);
                        break;
                    }
                }
            }
        })
        function submitHandler() {
            if ($.validate.form()) {
                var config = {
                    url: prefix + "/editModel",
                    type: "POST",
                    dataType: "json",
                    async: false,
                    data: $('#form-interface-add').serialize(),
                    success: function (result) {

                    }
                };
                $.ajax(config);
            }
        }

        function resetHandler() {
            var config = {
                url: prefix + "/editModel?id="+$("#id").val(),
                type: "POST",
                dataType: "json",
                async: false,
                success: function (result) {

                }
            };
            $.ajax(config);
        }
    </script>
</body>
</html>